/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rie06.openvoip.client.IHM.home;

import com.rie06.openvoip.client.Contact;
import com.rie06.openvoip.client.Conversation;
import com.rie06.openvoip.client.IHM.communication.CommunicationController;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import javax.swing.JPanel;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author Sylvain
 */
public class PanelRequest extends JPanel {

    private static final Logger logger = Logger.getLogger(PanelRequest.class);
    private CommunicationController communicationController;
    private InterfaceClient interfaceClient;

    public PanelRequest(InterfaceClient interfaceClient, CommunicationController communicationController) {

        this.interfaceClient = interfaceClient;
        this.communicationController = communicationController;


        this.setPreferredSize(new Dimension(190, 800));

    }

    public void updateListRequest() {

        this.removeAll();

        HashMap m = (HashMap) interfaceClient.getClient().getConversationList();
        for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
            Map.Entry<UUID, Conversation> entry = (Map.Entry<UUID, Conversation>) it.next();

            UUID uuid = entry.getKey();
            Conversation conversation = entry.getValue();

            Contact contact = null;
            if (conversation.isMaster()) {
                logger.log(Level.DEBUG, "aaa_Contact Size: "+conversation.getContactList().values().toArray().length);
                contact = (Contact)conversation.getContactList().values().toArray()[0];
            } else {
                contact = (Contact) interfaceClient.getClient().getContactList().get(conversation.getMasterContactUUID());
            }
            PanelRequestConversation panelRequestConversation = new PanelRequestConversation(uuid, contact, interfaceClient, communicationController, conversation);

            logger.log(Level.INFO, "Update PanelRequest : ");
            logger.log(Level.DEBUG, "Description contact : " + contact.getName() + "Conversation : " + conversation.getUuid());

            this.add(panelRequestConversation);
            

        }
        this.repaint();
        this.revalidate();

    }

    public CommunicationController getCommunicationController() {
        return communicationController;
    }

    public InterfaceClient getInterfaceClient() {
        return interfaceClient;
    }
}
